using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using System.Drawing.Design;
using System.Windows.Forms.Design;

namespace UrduCtrl
{
	/// <summary>
	/// Summary description for UrduComboBox.
	/// </summary>
	public class UrduComboBox : System.Windows.Forms.ComboBox
	{
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;
		private ComboBox.ObjectCollection listItems=null;

		public UrduComboBox()
		{
			// This call is required by the Windows.Forms Form Designer.
			InitializeComponent();

			listItems= new ComboBox.ObjectCollection(this);
			listItems.Add("Test");
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if( components != null )
					components.Dispose();
			}
			base.Dispose( disposing );
		}

		#region Component Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify 
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			components = new System.ComponentModel.Container();

			this.Font = new System.Drawing.Font("Urdu Naskh Asiatype", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(178)));
			this.RightToLeft = System.Windows.Forms.RightToLeft.Yes;
		}
		#endregion

		protected override void OnPaint(PaintEventArgs pe)
		{
			// TODO: Add custom paint code here

			// Calling the base class OnPaint
			base.OnPaint(pe);
		}

		[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
		[Category("Appearance"), 
		Description("The items in the list box."), 
		Editor(typeof(UrduComboBoxItemPropertyEditor), typeof(UITypeEditor))]
		new public ComboBox.ObjectCollection Items
		{
			get { return this.listItems; }
		}
	}

	public class UrduComboBoxItemPropertyEditor: UITypeEditor
	{

		public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
		{
			if (context!=null && provider!=null)
			{
				IWindowsFormsEditorService edSrv= (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
				if (edSrv!=null)
				{					
					UrduTextListEditorForm dialog= new UrduTextListEditorForm();
					//					if (value is ListBox.ObjectCollection)
					//					{
					//						MessageBox.Show("Test");
					//						dialog.Lines= (ListBox.ObjectCollection)value;	
					//					}
					if (edSrv.ShowDialog(dialog)==System.Windows.Forms.DialogResult.OK)
					{
						//MessageBox.Show("before");
						((ComboBox.ObjectCollection) value).AddRange(dialog.Lines);
						//value= dialog.Lines;
						//MessageBox.Show((String) value);
						
					}
					else
						MessageBox.Show("Failed!");
					dialog.Dispose();
					dialog= null;
				}
			}
			return value;
		}

		public override System.Drawing.Design.UITypeEditorEditStyle 
			GetEditStyle(System.ComponentModel.ITypeDescriptorContext context) 
		{ 
			// We will use a window for property editing. 
			return UITypeEditorEditStyle.Modal; 
		}

		public override bool GetPaintValueSupported( 
			System.ComponentModel.ITypeDescriptorContext context) 
		{ 
			// No special thumbnail will be shown for the grid. 
			return false; 
		} 
	}
}
